package com.yanqu.road.server.cmd.activity.twins.cross;

import com.yanqu.road.entity.activity.twins.config.TwinsConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TwinsProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.twins.TwinsMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

@Cmd(code = GameProtocol.S_TWINS_CROSS_LUCK_DRAW_RECORD_SYNC, desc = "")
public class CrossTwinsLuckDrawRecordSyncCmd extends AbstractCommand {

    TwinsProto.TwinsLuckDrawRecordSyncMsg reqMsg;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = TwinsProto.TwinsLuckDrawRecordSyncMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        TwinsConfig config = TwinsMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        List<GamePlayer> playerList = GamePlayerMgr.getAllOnlinePlayer();
        for(GamePlayer gamePlayer : playerList){
            gamePlayer.sendPacket(ClientProtocol.U_TWINS_LUCK_DRAW_RECORD_SYNC, reqMsg.toBuilder());
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }
    }
}
